package com.liuyu.common.framework.feignclient.api.feign.interceptor;

import cn.hutool.crypto.SmUtil;
import lombok.extern.slf4j.Slf4j;

/**
 * @ClassName SignUtil
 * @Description: 签名以及验证
 * @Author: liuyu
 * @Date: Created in 2020/10/15 9:40
 * @Version: 1
 * @Modified By:
 */
@Slf4j
public class PowerCloudSignUtil {
    /**
     * s = SecureUtil.md5(builder.toString());
     *
     * @param arr
     * @return java.lang.String
     * @description 签名
     * @author liuyu
     * @date 2020/10/15 9:46
     */
    public static String sign(String[] arr) {
        StringBuilder builder = new StringBuilder();
        for (String s : arr) {
            builder.append(s);
        }
        String s = "";
        try {
            s = SmUtil.sm3(builder.toString());
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }
        return s;
    }

    /**
     * @param arr
     * @param signature
     * @return boolean
     * @description 验证
     * @author liuyu
     * @date 2020/10/15 9:46
     */
    public static boolean verify(String[] arr, String signature) {
        String s = sign(arr);

        if (s.equals(signature)) {
            return true;
        }
        return false;
    }

}
